package base.thread_JUC2.chapter03.demo04;

import java.util.Random;

/**
 * 矩阵类
 */
public class MatrixMock {
    private int data[][];

    /**
     * @param size 行数
     * @param length 列数
     * @param number 待查找数字值
     */
    public MatrixMock(int size, int length, int number){
        int counter = 0;
        data = new int[size][length];
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < length; j++) {
                data[i][j] = random.nextInt(10);
                if (data[i][j] == number) {
                    counter++;
                }
            }
        }
        System.out.printf("Mock: 在生成的数据中有 %d 次出现 %d.\n",counter,number);
    }

    public int[] getRow(int row){
        if ((row>=0)&&(row<data.length)){
            return data[row];
        }
        return null;
    }

    public static void main(String[] args) {
        MatrixMock matrixMock = new MatrixMock(10, 10, 5);
        int[] row = matrixMock.getRow(2);
        System.out.println(row);
    }


}
